package com.sf.fy.uav.applet.controller.operate;

import com.sf.fy.uav.applet.service.SysNoticeService;
import com.sf.fy.uav.common.request.common.IdRequest;
import com.sf.fy.uav.common.request.operate.*;
import com.sf.fy.uav.common.request.order.DealRequest;
import com.sf.fy.uav.common.response.operational.SysNoticeResponse;
import com.sf.fy.uav.common.utils.Rs;
import com.sf.fy.uav.controller.NoticeRest;
import com.sf.fy.uav.service.INoticeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author LTQ
 */
@RestController
@RequestMapping("/home/notice/")
@Tag(name = "通知管理")
public class SysNoticeController {

    private final static Logger logger = LoggerFactory.getLogger(SysNoticeController.class);
    @Autowired
    private NoticeRest noticeRest;

    @Autowired
    private INoticeService iNoticeService;


    @Autowired
    private SysNoticeService sysNoticeService;


    public Rs<SysNoticeResponse> getById(@RequestParam String bannerId) {
        return Rs.success(noticeRest.getById(bannerId));
    }

    @GetMapping("get-notices")
    @CrossOrigin
    public Rs<List<SysNoticeResponse>> getNotices(@RequestParam Integer page, @RequestParam Integer size, @RequestParam(required = false) String name, @RequestParam(required = false) Integer status) {
        SysNoticeRequest sysNoticeRequest = new SysNoticeRequest();
        sysNoticeRequest.setPage(page);
        sysNoticeRequest.setSize(size);
        sysNoticeRequest.setStatus(status);
        sysNoticeRequest.setName(name);
        return Rs.success(noticeRest.getNotices(sysNoticeRequest));
    }

    @GetMapping("get-total")
    @CrossOrigin
    public Rs<Long> getTotal(@RequestParam(required = false) String name, @RequestParam(required = false) Integer status) {
        return Rs.success(noticeRest.getTotal(name, status));
    }

    @PostMapping("add")
    @CrossOrigin
    public Rs<Void> add(@RequestBody SysNoticeAddRequest sysNoticeAddRequest) {
        sysNoticeService.add(sysNoticeAddRequest);
        return Rs.success();
    }

    @PostMapping("edit")
    @CrossOrigin
    public Rs<Void> edit(@RequestBody SysNoticeEditRequest sysNoticeEditRequest) {
        sysNoticeService.edit(sysNoticeEditRequest);
        return Rs.success();
    }

    @PostMapping("off")
    public Rs<Void> off(@RequestBody DealRequest dealRequest) {
        noticeRest.off(dealRequest);
        return Rs.success();
    }

    public Rs<Integer> start(@RequestBody IdRequest idRequest) {
        return Rs.success(noticeRest.start(idRequest));
    }


    public Rs<Integer> end(@RequestBody IdRequest idRequest) {
        return Rs.success(noticeRest.end(idRequest));
    }

    @PostMapping("delete")
    public Rs<Void> delete(@RequestBody DealRequest dealRequest) {
        noticeRest.delete(dealRequest);
        return Rs.success();
    }


}
